package com.zhongfl.crm.model.boss;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.zhongfl.crm.enums.boss.WorkOrderSettleStatus;
import com.zhongfl.crm.enums.boss.WorkOrderTypeCode;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.apache.commons.lang3.StringUtils;
import org.springframework.format.annotation.DateTimeFormat;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Objects;

/**
 * tb_work_order_settle
 */
@Data
@ToString
public class WorkOrderSettle implements Serializable{

    private List<WorkOrderSettleConfirm> confirms;

    /**
     * 自增ID
     */
    private Integer id;

    /**
     * 结算单号
     */
    private String settleNo;

    /**
     * 订单号
     */
    private String orderNo;

    /**
     * 工单号
     */
    private String workOrderNo;

    /**
     * 付款阿米巴ID
     */
    private Integer fromAmibaId;

    /**
     * 付款阿米巴名称
     */
    private String fromAmibaName;

    /**
     * 收款阿米巴ID
     */
    private Integer toAmibaId;

    /**
     * 收款阿米巴名称
     */
    private String toAmibaName;

    /**
     * 发起人员工编码
     */
    private String submitStaffCode;

    /**
     * 发起人姓名
     */
    private String submitStaffName;

    /**
     * 发起结算时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date submitTime;

    /**
     * 外部收入
     */
    private BigDecimal outsiteIncomeAmount;

    /**
     * 外部收入实收金额
     */
    private BigDecimal outsiteIncomeReceivedAmount;

    /**
     * 外部收入挂账金额
     */
    private BigDecimal outsiteIncomeChargeAmount;

    /**
     * 内部收入
     */
    private BigDecimal insiteIncomeAmount;

    /**
     * 共支出金额
     */
    private BigDecimal totalOutcomeAmount;

    /**
     * 状态, 待结算 已结算
     */
    private WorkOrderSettleStatus status;

    private String statusName;

    public String getStatusName() {
        if (Objects.nonNull(status)) {
            return status.getDesc();
        }
        return StringUtils.EMPTY;
    }

    /**
     * 结算完成时间, 双方领导确认时间点
     */
    private Date settledTime;

    /*工单结算单关系人信息对象*/
    private WorkOrderSettleStaffs staffs;

    /*工单类型名称*/
    private String workOrderTypeCodeName;

    /**
     * 挂账责任方
     */
    private CreditParty creditParty;

    private String creditPartyName;

    public String getCreditPartyName() {
        if (Objects.nonNull(creditParty)) {
            return creditParty.getKey();
        }
        return StringUtils.EMPTY;
    }

    /**
     * 工单备注描述
     */
    private String remark;

    /**
     * 逻辑删除标记 0未删1已删
     */
    private Integer deleted;

    /**
     * 创建人
     */
    private String createdBy;

    /**
     * 创建时间
     */
    private Date createdTime;

    /**
     * 最后更新人
     */
    private String modifiedBy;

    /**
     * 更新时间
     */
    private Date modifiedTime;

    //以下是订单信息

    /*客户姓名*/
    private String name;

    /*客户手机号*/
    private String mobile;


    /*商务经理手机号*/
    private String businessManagerMobile;


    /*交付经理经理手机号*/
    private String deliverManagerMobile;

    private Integer businessManagerAmibaId;
    private String businessManagerAmibaName;
    private Integer deliverManagerAmibaId;
    /*商务经理*/
    private String businessManager;


    /*交付经理的StaffCode*/
    private String deliverManagerStaffCode;


    /*商务经理的StaffCode*/
    private String businessManagerStaffCode;

    /*交付经理*/
    private String deliverManager;

    /*订单渠道名称*/
    private String channelName;

    /*借款金额*/
    private BigDecimal loanAmount;

    /*贷款利率*/
    private BigDecimal rate;

    /*总服务费率*/
    private BigDecimal totalFeeRate;

    /*服务费金额*/
    private BigDecimal serviceAmount;

    /*渠道佣金费率*/
    private BigDecimal channelRate;

    /*渠道佣金金额*/
    private BigDecimal channelFee;

    /**
     * 工单类型代码
     */
    @Setter
    @Getter
    private WorkOrderTypeCode workOrderTypeCode;
    /*工单类型名称*/
    public String getWorkOrderTypeCodeName() {
        if(StringUtils.isNotEmpty(workOrderTypeCodeName)){
            return workOrderTypeCodeName;
        }
        if (workOrderTypeCode != null) {
            return workOrderTypeCode.getValue();
        }
        return "";
    }

    /*评分*/
    private Integer grade;

    /*评分评价*/
    private String evaluation;

    /*用于判断当前登录人是否确认结算*/
    private Boolean isConfirm;

    /* 办理员工 */
    private String claimStaffCode;
    private String claimStaffName;

    /* 分行 */
    private String branchBank;

    private String receiveAmibaName;

    private String receiveAmibaId;

    /* 是否云讯评价 */
    private Boolean isEvaluation;

    /**
     * 订单的批贷金额
     */
    private BigDecimal approvalAmount;

    /**
     * 是否一次性批贷
     */
    private Integer passByOneTime;

    /**
     * 批贷期限（月）
     */
    private Integer loanDuration;

    /**
     * 非一次性批贷原因
     */
    private String approveReason;

    /**
     * 是否一次性放款
     */
    private Integer oneTimeLoaned;

    /**
     * 非一次性放款原因
     */
    private String loanedReason;

    /**
     * 房本入库时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date houseEntryTime;
}